package uk.ac.aber.Blockmation;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import java.util.Observable;
import java.util.Vector;
/**
 * Movie model class. Holds all frames of a movie and information about
 * the delay default between frames. 
 * Frames are stored as BufferedImages in Vector object.
 * This class uses only Vector class methods to access and modify existing
 * frames so relies on Vector implementation.
 *
 * @author Aron, alex (minor modifications)
 *
 */
public class MovieModel
{
	/** Holds all frames */
	private Vector<BufferedImage> frames = new Vector<BufferedImage>();
	private int speed = 500;

	/**
	 * Constructs empty object.
	 */
	public MovieModel()
	{
	}
	/**
	 * Constructs object with specific delay between frames.
	 * @param speed - speed of animation (the delay between frames).
	 */
	MovieModel(int speed)
	{	
		this.speed = speed;
	}

	/**
	 * Appends frame to current set of frames.
	 * @param frame - inserting frame
	 */
	public void appendFrame(BufferedImage frame)
	{
		frames.add(frame);
	}

	/**
	 * Potential use in the future.
	 * @param index
	 * @param frame
	 */
	public void insertFrameAt(int index, BufferedImage frame)
	{
		frames.add(index, frame);
	}
	/**
	 * Potential use in the future.
	 * @param index
	 * @param framesSet
	 */
	public void insertFramesAt(int index, Vector<BufferedImage> framesSet)
	{
		frames.addAll(index, framesSet);
	}

	/**
	 * Gets the frame at the position of index 
	 * @param index
	 * @return frame as BufferedImage
	 */
	public BufferedImage get(int index) 
	{
		return frames.get(index);
	}

	/**
	 * 
	 * @return speed/delay between frames 
	 */
    public int getSpeed() {
        return speed;
    }

    /**
     * Sets delay between frames.
     * @param speed
     */
	public void setSpeed(int speed)
	{
		this.speed = speed;
	}

	public String toString()
	{
		return "totalFrames: " + frames.size() + " ,speed: " + speed;
	}

	/**
	 * Swaps the frame at index position with new frame (image).
	 * @param index - position in the Vector
	 * @param image - replacement
	 */
	public void setFrame(int index, BufferedImage image) {
        frames.set(index, image);
        }

	/**
	 * 
	 * @return number of frames
	 */
	public int size() {
        return frames.size();
    }
        
	/**
	 * Removes frame at index.
	 * @param index
	 */
	public void removeFrame(int index) {
        frames.removeElementAt(index);
   }
        
}
